<?php TPL::output('admin/global/header.tpl.htm'); ?>
<?php TPL::output('admin/global/nav_menu.tpl.htm'); ?>

<div class="aw-content-wrap">
    <div class="mod">
        <div class="mod-head">
            <h3>
                <span class="pull-left"><?php _e('自定义回复'); ?></span>
            </h3>

            <?php if (count($this->accounts_list) > 1) { ?>
            <div class="dropdown pull-right">
                <a class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
                    <?php if ($this->account_info['id'] === 0) { _e('主账号'); } else { _e('子账号 %s', $this->account_info['id']); } ?>
                    <span class="caret"></span>
                </a>

                <ul class="dropdown-menu weixin-dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                    <?php foreach ($this->accounts_list AS $account_info) {
                        if ($account_info['id'] == $this->account_info['id']) { continue; } ?>
                    <li role="presentation">
                        <a role="menuitem" tabindex="-1" href="admin/weixin/reply/id-<?php echo $account_info['id']; ?>"><?php if ($account_info['id'] == 0) { _e('主账号'); } else { _e('子账号 %s', $account_info['id']); } ?></a>
                    </li>
                    <?php } ?>
                </ul>
            </div>
            <?php } ?>
        </div>

        <div class="tab-content mod-body">
            <div class="alert alert-success collapse error_message"></div>

            <div class="table-responsive">
                <form action="admin/ajax/weixin/save_reply_rule_status/" method="post" id="rule_list_form" onsubmit="return false">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th><?php _e('启用'); ?></th>
                        <th width="20%"><?php _e('关键词'); ?></th>
                        <th><?php _e('排序'); ?></th>
                        <th><?php _e('回应内容'); ?></th>
                        <th><?php _e('设为欢迎信息'); ?></th>
                        <th><?php _e('设为无匹配回复'); ?></th>
                        <th><?php _e('操作'); ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <input type="hidden" name="account_id" value="<?php echo $this->account_info['id']; ?>" />

                    <?php if ($this->rule_list) { foreach ($this->rule_list AS $rule_info) { ?>
                    <input type="hidden" name="rule_ids[]" value="<?php echo $rule_info['id']; ?>" />
                    <tr>
                        <td><input type="checkbox" class="enabled-status" name="enabled_status[<?php echo $rule_info['id']; ?>]" value="1"<?php if ($rule_info['enabled']) { ?> checked="checked"<?php } ?> /></td>
                        <td><?php echo $rule_info['keyword']; ?></td>
                        <td><?php if ($rule_info['image_file']) { ?>
                            <input type="text" class="form-control sort-action sort-status input-mini" name="sort_status[<?php echo $rule_info['id']; ?>]" value="<?php echo $rule_info['sort_status']; ?>" />
                            <?php } else { ?> - <?php } ?>
                        </td>
                        <td><?php if ($rule_info['image_file']) { ?><span class="label label-info"><?php _e('图文消息'); ?></span> <?php } ?><?php echo $rule_info['title']; ?></td>
                        <td><?php if (!$this->echo_rule_list[$rule_info['keyword']]) { ?><input class="flag-action" type="radio" value="<?php echo $rule_info['keyword']; ?>" name="is_subscribe"<?php if ($this->account_info['weixin_subscribe_message_key'] == $rule_info['keyword']) { ?> checked="checked"<?php } ?> /><?php } else { ?>-<?php } ?></td>
                        <td><?php if (!$this->echo_rule_list[$rule_info['keyword']]) { ?><input class="flag-action" type="radio" value="<?php echo $rule_info['keyword']; ?>" name="is_no_result"<?php if ($this->account_info['weixin_no_result_message_key'] == $rule_info['keyword']) { ?> checked="checked"<?php } ?> /><?php } else { ?>-<?php } ?></td>
                        <td class="nowrap">
                            <a href="admin/weixin/reply_edit/id-<?php echo $rule_info['id']; ?>" data-toggle="tooltip" class="icon icon-edit md-tip" title="<?php _e('编辑'); ?>"></a>
                            <a onclick="AWS.ajax_request(G_BASE_URL + '/admin/ajax/weixin/remove_reply_rule/', 'id=<?php echo $rule_info['id']; ?>');" data-toggle="tooltip" class="icon icon-trash md-tip" title="<?php _e('删除'); ?>"></a>
                        </td>
                    </tr>
                    <?php } } ?>
                    </tbody>
                </table>
                </form>
                <div class="mod-table-foot mod-one-btn">
                    <a class="btn btn-primary" href="admin/weixin/reply_edit/account_id-<?php echo $this->account_info['id']; ?>" id="batch_approval"><?php _e('添加规则'); ?></a>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $('input.enabled-status, input.flag-action').on('ifChanged', function () {
            if ($(this).val() != '')
            {
                AWS.ajax_post($('#rule_list_form'), AWS.ajax_processer, 'error_message');
            }
        });

        $('input.sort-action').keyup(function () {
            if ($(this).val() != '')
            {
                AWS.ajax_post($('#rule_list_form'), AWS.ajax_processer, 'error_message');
            }
        });
    });
</script>

<?php TPL::output('admin/global/footer.tpl.htm'); ?>